package com.zh.webcommon.upload.config;

import com.zh.webcommon.upload.FileUploadClient;
import com.zh.webcommon.upload.MinioUploadProperties;
import io.minio.MinioClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 文件服务minio配置
 * @author ZH
 * @date 23:39 2022/1/7
 */
@Slf4j
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(MinioUploadProperties.class)
public class MinioClientAutoConfigure {
    static {
        log.info("MinioClientAutoConfigure auto configure ....");
    }

    @Bean
    public MinioClient minioClient(MinioUploadProperties minioUploadProperties) {
        return MinioClient.builder()
                .endpoint(minioUploadProperties.getEndpoint())
                .credentials(minioUploadProperties.getAccessKey(),minioUploadProperties.getSecretKey())
                .build();
    }

    @Bean
    public FileUploadClient fileUploadClient(MinioClient minioClient, MinioUploadProperties minioUploadProperties){
        return new FileUploadClient(minioClient,minioUploadProperties);
    }

}
